<!--
* description: 车辆管理-库存查询
* author: ligy
* createdDate: 2020-11-18
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :dynamic-api-style="'restful'"
    />
  </div>
</template>

<script>
// import { formMixins } from '@/components/mixins/formMixins'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { exportExcel } from '@/utils/getTimeString.js'
import api from '@/api/vehicleManagement'
import lov from '@/api/Lov'

export default {
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins],
  data() {
    return {
      dynamicApiConfigs: api.inventoryQuery,
      // 动态生成网格列
      tableCols: [
        {
          prop: 'vin',
          label: 'VIN',
          width: 180
        },
        {
          prop: 'salesPlanCode',
          label: '销售计划号',
          width: 180
        },
        {
          prop: 'moveStateCn',
          label: '车辆流转状态'
        },
        {
          prop: 'isCarState',
          label: '车辆状态'
        },
        {
          prop: 'hostLimitrEasonCn',
          label: '限制类型'
        },
        {
          prop: 'hostQualityStateCn',
          label: '质量状态'
        },
        {
          prop: 'assignState',
          label: '配车状态'
        },
        {
          prop: 'discardSetNamekuang',
          label: '车辆是否报废'
        },
        {
          prop: 'discardTypeName',
          label: '报废类型'
        },
        {
          prop: 'discardDesc',
          label: '报废原因'
        },
        {
          prop: 'discardDate',
          label: '报废时间',
          width: 180
        },
        {
          prop: 'QmsState',
          label: '锁车状态',
          width: 180
        },
        {
          prop: 'lockCode',
          label: '锁车码',
          width: 180
        },
        {
          prop: 'lockPosition',
          label: '锁车车间/位置',
          width: 180
        },
        {
          prop: 'lockReason',
          label: '锁车原因',
          width: 180
        },
        {
          prop: 'lockBeginDate',
          label: '锁车限制开始日期',
          width: 180
        },
        {
          prop: 'lockEndDate',
          label: '锁车限制结束日期',
          width: 180
        },
        {
          prop: 'assignDate',
          label: '配车时间',
          width: 180
        },
        {
          prop: 'firstInHoststockDate',
          label: '总部入库时间',
          width: 180
        },
        {
          prop: 'firstInDlrstockDate',
          label: '门店入库时间',
          width: 180
        },
        {
          prop: 'offlineTime',
          label: '下线日期',
          width: 180
        },
        {
          prop: 'finalTime',
          label: '生产日期',
          width: 180
        },
        {
          prop: 'date',
          label: '库存天数'
        },
        {
          prop: 'carHouseName',
          label: '仓库'
        },
        {
          prop: 'cityName',
          label: '交付城市'
        },
        {
          prop: 'carLicense',
          label: '车牌号'
        },
        {
          prop: 'SaleStatus',
          label: '车型销售状态'
        },
        {
          prop: 'ttCode',
          label: '22位码',
          width: 180
        },
        {
          prop: 'carSeriesCode',
          label: '车系编码'
        },
        {
          prop: 'carSeriesCn',
          label: '车系名称'
        },
        {
          prop: 'carConfigCode',
          label: '基础车型编码',
          width: 180
        },
        {
          prop: 'carConfigCn',
          label: '基础车型名称',
          width: 180
        },
        {
          prop: 'optionalPagCode',
          label: '选装包编码'
        },
        {
          prop: 'optionalPagName',
          label: '选装包名称',
          width: 180
        },
        {
          prop: 'carColorCode',
          label: '车身颜色编码'
        },
        {
          prop: 'carColorName',
          label: '车身颜色'
        },
        {
          prop: 'carIncolorCode',
          label: '内饰颜色'
        },
        {
          prop: 'carIncolorName',
          label: '内饰颜色'
        }
      ],
      tableComponents: [
        {
          compKey: 'compKey1',
          labelName: '车系：',
          codeField: 'carSeriesId',
          oFields: 'carSeriesId,carSeriesCn',
          customObj: {
            api: lov.listOfCarSeries
          },
          component: () => import('@/components/org/commonSelect'),
          type: 'dropdownList',
          isMul: false,
          isMust: true
        },
        {
          compKey: 'compKey2',
          labelName: '基础车型：',
          codeField: 'carConfigId',
          component: () => import('@/components/org/commonSelect'),
          oFields: 'carConfigId,carConfigCn',
          parentFileds: 'value:carSeriesId',
          customObj: {
            listQuery: { carSeriesId: '' },
            api: lov.queryCarType
          },
          type: 'dropdownList',
          isMul: false,
          isMust: true
        },
        {
          compKey: 'compKey3',
          labelName: '选装包：',
          codeField: 'optionalPagId',
          component: () => import('@/components/org/commonSelect'),
          parentFileds: 'value:carConfigId',
          oFields: 'optionalPagId,optionalPagName',
          customObj: {
            api: lov.queryCarOptionalPagLinkMessage,
            listQuery: {
              carConfigId: ''
            }
          },
          type: 'dropdownList',
          isMul: false,
          isMust: true
        },
        {
          compKey: 'compKey4',
          labelName: '车身颜色：',
          codeField: 'carColorId',
          component: () => import('@/components/org/commonSelect'),
          oFields: 'carColorId,carColorName',
          parentFileds: 'value:carConfigId|carSeriesId|optionalPagId',
          customObj: {
            listQuery: {
              carConfigId: '', carSeriesId: '', optionalPagId: ''
            },
            api: lov.queryCarColorLinkMessage
          },
          type: 'dropdownList',
          isMul: false,
          isMust: true
        },
        {
          compKey: 'compKey5',
          labelName: '内饰颜色：',
          codeField: 'carIncolorId',
          component: () => import('@/components/org/commonSelect'),
          oFields: 'carIncolorId,carIncolorName',
          parentFileds: 'value:carConfigId|carSeriesId|optionalPagId',
          customObj: {
            listQuery: {
              carConfigId: '', carSeriesId: '', optionalPagId: ''
            },
            selectType: '1',
            api: lov.queryCarInColorLinkMessage
          },
          type: 'dropdownList',
          isMul: false,
          isMust: false
        },
        {
          compKey: 'compKey6',
          labelName: '22位码：',
          codeField: 'ttCode',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false,
          span: 6
        },
        // 库存状态
        {
          compKey: 'compKey7',
          labelName: '车辆流转状态：',
          codeField: 'moveState',
          lookuptype: 'VE0212',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: false,
          span: 6
        },
        // 车辆状态
        {
          compKey: 'compKey8',
          labelName: '车辆状态：',
          codeField: 'isCarState',
          lookuptype: 'VE0207',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: false,
          span: 6
        },
        {
          compKey: 'compKey9',
          labelName: '车辆是否报废：',
          codeField: 'discardSet',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: false,
          span: 6,
          oFields: 'discardSet,discardSetName',
          options: [
            { discardSet: '0', discardSetName: '未报废' },
            { discardSet: '1', discardSetName: '已报废' }
          ]
        },
        // 入库仓库
        {
          compKey: 'compKey10',
          labelName: '入库仓库：',
          codeField: 'stockName',
          component: () => import('@/components/ve/carStockHouse'),
          dataToObject: { warehouseId: '5' },
          type: 'dropdownList',
          isMust: false,
          span: 6
        },
        // 审核状态
        {
          compKey: 'compKey11',
          labelName: '配车状态：',
          codeField: 'assignState',
          component: () => import('@/components/org/userSeleapiConfig'),
          oFields: 'AsId,AsText',
          options: [
            { AsId: '1', AsText: '已配车' },
            { AsId: '0', AsText: '待配车' }
          ],
          type: 'inputText',
          isMust: false,
          span: 6
        },
        // VIN码
        {
          compKey: 'compKey12',
          labelName: 'VIN码：',
          codeField: 'vin',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false,
          span: 6
        },
        // 销售计划号查询
        {
          compKey: 'compKey13',
          labelName: '销售计划号：',
          codeField: 'salesPlanCode',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false,
          span: 6
        },
        // 入库时间
        {
          compKey: 'compKey14',
          labelName: '入库时间：',
          codeField: 'startTime,endTime',
          component: () => import('@/components/org/datePicker/datePicker'),
          dateType: 'daterange',
          isMust: false,
          span: 6
        },
        // 质量状态
        {
          compKey: 'compKey15',
          labelName: '质量状态：',
          codeField: 'hostQualityState',
          lookuptype: 'VE0268',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: false,
          span: 6
        },
        // 车辆类型
        {
          compKey: 'compKey16',
          labelName: '限制类型：',
          codeField: 'hostLimitState',
          lookuptype: 'VE1033',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: false,
          span: 6
        },
        {
          compKey: 'compKey17',
          labelName: '车型销售状态：',
          codeField: 'SaleStatus',
          lookuptype: 'VE1323',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: false,
          span: 6
        }
      ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          text: '查询',
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey2',
          type: '',
          size: 'small',
          text: '重置',
          clickEvent: () => this.reset(),
          position: 'right'
        },
        {
          conmpKey: 'btenKey3',
          type: '',
          size: 'small',
          text: '导出',
          clickEvent: () => this.exportExcel111(api.exporDetailed, '库存查询'),
          position: 'left'
        }
      ],
      formField: {
        moveState: '',
        carSeriesId: '',
        carConfigId: '',
        optionalPagId: '',
        carColorId: '',
        carIncolorId: '',
        ttCode: '',
        SaleStatus: '',
        isCarState: '',
        carStockHouseId: '',
        assignState: '',
        discardSet: '',
        vin: '',
        startTime: '',
        endTime: '',
        hostQualityState: '',
        hostLimitState: '',
        stockId: '',
        stockName: '',
        stockCode: '',
        salesPlanCode: ''
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      if (this.$store.getters.orgInfo.DLR_ID === 'HOST') {
        this.tableComponents.forEach(item => {
          if (item.codeField === 'stockName') {
            item.dataToObject.warehouseId = '1'
          }
        })
      }
    })
  },
  methods: {
    exportExcel111(api, title) {
      exportExcel(this.formField, api.APIUrl, 'export', title)
    }
  }
}
</script>

<style>
</style>
